#include "s_lcd.h"
#include "s_st7735.h"
#include "s_font.h"

void s_lcd_fill(unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned short color)
{
	s_st7735_fill_window(x, y, x + width - 1, y + height - 1, color);
}

void s_lcd_set_window(unsigned short x, unsigned short y, unsigned short width, unsigned short height)
{
	s_st7735_set_window(x, y, x + width - 1, y + height - 1);
}

void s_lcd_write_16bit(unsigned short data)
{
	s_st7735_write_16bit_data(data);
}

void s_lcd_show_char(unsigned short x, unsigned short y, \
	unsigned short fc, unsigned short bc, \
	unsigned char char_num, unsigned char char_size)
{
	unsigned char temp;
    unsigned char pos,t;
     
		   
	char_num = char_num - ' ';//µÃµ½Æ«ÒÆºóµÄÖµ
	s_lcd_set_window(x, y , char_size/2, char_size);//ÉèÖÃµ¥¸öÎÄ×ÖÏÔÊ¾´°¿Ú	
	for(pos=0; pos < char_size; pos++)
	{
		if(char_size == 12) {
			temp=asc2_1206[char_num][pos];
		} else {
			temp=asc2_1608[char_num][pos];
		}
		for(t=0;t<char_size/2;t++)
	    {                 
	        if(temp&0x01)s_lcd_write_16bit(fc); 
			else s_lcd_write_16bit(bc); 
			temp>>=1; 
			
	    }
		
	}	

	// POINT_COLOR=colortemp;	
	// LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//»Ö¸´´°¿ÚÎªÈ«ÆÁ    	   	 	  
}

void s_lcd_show_string(unsigned short x, unsigned short y, \
	unsigned short fc, unsigned short bc, \
	unsigned char *data, unsigned short len , unsigned char char_size)
{         
	while(len--) {
		if(x > 128 || y > 128) {
			return;
		}
		s_lcd_show_char(x, y, fc, bc, *data++, char_size);
		x += char_size / 2;
	}
} 

void s_lcd_show_pic(unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned char *pic)
{
	int i; 
	unsigned char picH,picL; 
	s_lcd_set_window(x, y, width, height);

    for(i=0;i<width * height;i++)
	{	
	 	picL=*(pic+i*2);	//Êý¾ÝµÍÎ»ÔÚÇ°
		picH=*(pic+i*2+1);				
		s_lcd_write_16bit(picH<<8|picL);  						
	}	
	// LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//»Ö¸´ÏÔÊ¾´°¿ÚÎªÈ«ÆÁ	
}

signed char s_lcd_init(void)
{
	s_st7735_init();

	// s_lcd_show_char(0, 0, 0x00, 0xFFFF, '8', 12);
	// s_lcd_show_char(0, 12, 0x00, 0xFFFF, '8', 16);
	s_lcd_show_string(0, 0, 0xFFFF, 0x00, "Test", 4, 12);
	s_lcd_show_string(0, 12, 0xFFFF, 0x00, "Test", 4, 16);
	return 0;
}
